//
//  YYQuestionVC.m
//  drivingSchool
//
//  Created by 子yu 刘 on 2018/8/15.
//  Copyright © 2018年 子yu 刘. All rights reserved.
//

#import "YYQuestionVC.h"
#import "YYQuertionCell.h"
#import "YYQuestionDetailVC.h"

@interface YYQuestionVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)NSArray * dataArr;
@property (nonatomic ,copy)NSString * phone;

@end

@implementation YYQuestionVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self getData];
}

- (void)getData{
    [RequestOperationManager perdonlCustomer_success:^(id result) {
        if (DEF_REQ_SUCCESS) {
            self.dataArr = result[@"data"][@"list"][@"data"];
            self.phone = result[@"data"][@"phone"][@"iphone"];
            [self.tableView reloadData];
        }
        
    } failture:^(NSError *error) {
        
    }];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 48;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    YYQuertionCell * cell = [tableView dequeueReusableCellWithIdentifier:@"YYQuertionCell"];
    NSDictionary * itme = self.dataArr[indexPath.row];
    cell.lbTitle.text = itme[@"title"];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    YYQuestionDetailVC * detail = (YYQuestionDetailVC *)[CFUtility getVC:@"YYQuestionDetailVC" Storyboard:MINE];
    detail.dict = self.dataArr[indexPath.row];
    [self.navigationController pushViewController:detail animated:YES];
}
- (IBAction)consult:(id)sender {
    {
        NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@",self.phone];
        if (@available(iOS 10.0, *)) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone] options:@{} completionHandler:nil];
        } else {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
        }
        
        
        
    }
}


@end
